<?php


namespace App\Http\Controllers\Api;


use App\Http\Controllers\Controller;
use App\Models\Integral;
use App\Models\IntegralUsers;
use App\Models\Service;
use App\Models\Users;
use Illuminate\Http\Request;

class OtherController extends Controller
{
    //积分
    public function getMyIntegral()
    {
        $user_id = $this->uId;
        $totalIntegral = Users::where('id', $user_id)->value('integral');
        $todayIntegral = IntegralUsers::where('user_id', $user_id)->whereDate('created_at', today())->sum('integral');
        $integral = Integral::get();
        foreach ($integral as $value) {
            $total = IntegralUsers::where(['user_id' => $user_id, 'integral_id' => $value['id']])->whereDate('created_at', today())->count();
            if ($total >= $value['total']) {
                $value['finish'] = $total;
            } else {
                $value['finish'] = $total;
            }
        }
        $result['totalIntegral'] = $totalIntegral;
        $result['todayIntegral'] = $todayIntegral;
        $result['integral'] = $integral;
        return showMsg('获取成功', 200, $result);
    }

    //客服列表
    public function getService(Request $request)
    {
        $house_id = $request->get('id', 0);
        $result = Service::where('flag', 1)->where('house_id', $house_id)->get();
        foreach ($result as $value){
            if ($value['headimg']) {
                $value['headimg'] = getAliOssImage($value['headimg']);
            }
        }
        return showMsg('获取成功', 200, $result);
    }


}